"use strict";

define('Router', [
  'jquery', 'underscore', 'backbone',
  'HomeView',
  'ShopAroundView', 'OrderListView'

], function ($, _, Backbone,
             HomeView,
             ShopAroundView, OrderListView) {
  return Backbone.Router.extend({

    routes: {
      '': 'home',
      'home': 'home',

      // buy ware
      'shoparound': 'shoparound',
      // my order
      'order': 'order',

      //'order': 'order',
      //'ticket': 'ticket',
      // any other action defaults to the following handler
      '*actions': 'defaultAction'
    },
    initialize: function () {
      this.elms = {
        'page-content': $('.page-content')
      };
    },

    home: function () {
      console.log('router home');
      if (!this.homeView) this.homeView = new HomeView();
      this.elms['page-content'].html(this.homeView.render().el);
    },

    shoparound: function () {
      console.log('router shoparound');
      let self = this;
      if (!this.shopAroundView) this.shopAroundView = new ShopAroundView();
      this.shopAroundView.render(function () {
        self.elms['page-content'].html(self.shopAroundView.el);
      });
    },

    order: function () {
      console.log('router orderList');
      let self = this;
      if (!this.orderListView) this.orderListView = new OrderListView();
      this.orderListView.render(function () {
        self.elms['page-content'].html(self.orderListView.el);
      });
    }

  });
});
